import { Tree, Card } from 'antd';
import { useEffect, useState } from 'react';
import request from 'umi-request';

const initTreeData = [];

const TagTree = (props) => {
  const { onNodeSelect } = props;
  const [treeData, setTreeData] = useState(initTreeData);
  const [loading, setLoading] = useState(false);

  useEffect(async () => {
    const response = await request(`/eofficeserver/api/tag`);
    setTreeData(response);
    setLoading(loading);
  }, []);

  const onSelect = (keys, info) => {
    if (onNodeSelect) {
      onNodeSelect(keys, info);
    }
  };

  return (
    <>
      <Card loading={loading} title="标签" size="small">
        {!loading && <Tree defaultExpandAll onSelect={onSelect} treeData={treeData} />}
      </Card>
    </>
  );
};

export default TagTree;
